<template>
    <el-dialog class="eldialog" title="分配" :visible.sync="open" width="65%" append-to-body :before-close="closeDelDialog">
        <div>
            <el-form ref="queryForm"  :inline="true" v-show="showSearch">
                <el-form-item label="" v-for="(item, index) in listFrom" :key="index">
                    <span slot="label">{{ item.FIELD_CAPTION }} </span>
                    <input_item :item="item" @onChangeTap="onChangeTap" :inputType="1" :inputParams="queryParams">
                    </input_item>
                </el-form-item>
<!--                <el-form-item label="初审状态">
                    <el-select v-model="chushenstate" placeholder="请选择">
                        <el-option label="未审核" value="0"></el-option>
                        <el-option label="已审核" value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="复审状态">
                    <el-select v-model="fushenstate" placeholder="请选择">
                        <el-option label="未审核" value="0"></el-option>
                        <el-option label="已审核" value="1"></el-option>
                    </el-select>
                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search"  @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh"  @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>

        <el-divider></el-divider>
        <el-row>
            <el-col :span="24">
                <el-form :model="numInfo" :inline="true">
                    <el-form-item label="任务总数">
                        <el-input v-model="numInfo.ALLNUM" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="初审分配数">
                        <el-input v-model="numInfo.CHUSHENNUUM" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="复审分配数">
                        <el-input v-model="numInfo.FUSHENNUUM" disabled></el-input>
                    </el-form-item>

                </el-form>
            </el-col>

        </el-row>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(0)">初审手动分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(1)">初审平均分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(2)">复审手动分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(3)">复审平均分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(4)">重新初审分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(5)">重新复审分配</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus"  @click="onTaskTap(6)">人员调整</el-button>
            </el-col>
        </el-row>
        <!-- props: ["tableHeaderList", "tableData", "loading", "tableHeight","isRetrieval"], -->
        <tableList :tableHeaderList="tableHeaderList" :tableData="tableData" :loading="loading" :tableHeight="tableHeight"
            @sortChange="sortChange"></tableList>
        <pagination v-show="total > 0" :total="total" :page.sync="pageNum" :limit.sync="pageSize"
            @pagination="getdatalistbyrenwuidPost" />
        <openFinds v-if="openIs" :open="openIs" @closeDelfindDialog="closeDelfindDialog" :rowInfo="rowInfo"></openFinds>
        <turnover v-if="turnOpen" :open="turnOpen"  @closeDialog="closeDialog" :rowInfo="rowInfo"></turnover>
    </el-dialog>
</template>
<script>
import input_item from "@/components/input/index.vue"
import { getshowfield, getqueryfieldList } from "@/api/archive/fileCollection/offlinReception"
import { getjobinfo, getcsfsallnumbyrenwuid, getdatalistbyrenwuid, refp } from "@/api/archive/archivalAppraisal/bgqx/openArchivesAppraisal"
import { getLastIndexOf } from "@/utils/index.js"
import tableList from "@/components/tableList/index.vue"
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
import openFinds from '@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/assignTasks/openFinds.vue'
import turnover from '@/views/archive/archivalAppraisal/bgqx/openArchivesAppraisal/assignTasks/turnover.vue' //人员调整
export default {
    props: ['open', 'rowInfo'],
    components: {
        input_item,
        tableList,
        openFinds,
        turnover
    },
    data() {
        return {
            loading: false,
            listFrom: [], //查询框列表
            // 显示搜索条件
            showSearch: true,
            queryParams: {},
            searchcolumn: [],//查询参数
            chushenstate: undefined,//初审状态
            fushenstate: undefined,//复审状态
            numInfo: {
                ALLNUM: undefined,
                CHUSHENNUUM: undefined,
                FUSHENNUUM: undefined
            }, //获取总数/初审分配数/复审分配数
            pageNum: 1,
            pageSize: 10,
            total: 0,
            fields: [],//组装的表头table需要的参数
            tableHeaderList: [],
            tableData: [],
            tableHeight: "400",
            order: undefined,
            openIs: false,
            turnOpen:false

        }
    },
    watch: {
        rowInfo: {
            handler(valNew) {
                if (valNew) {
                    getjobinfo(valNew.ID).then(res => {
                        this.info = res.data.jobinfo;
                        this.getqueryfieldListPost(); /** 获取查询字段 */
                        this.getshowfieldPost();
                        this.getcsfsallnumbyrenwuidPost();//获取总数/初审分配数/复审分配数
                    })
                }
            }, immediate: true
        },
    },
    methods: {
        /** 获取查询字段 */
        getqueryfieldListPost() {
          var subtablename=this.info.SUB_TABLE_NAME;
          var type=subtablename.substring(subtablename.length-3,subtablename.length-2);
          if(type=='X'){
            subtablename=subtablename.substring(0,subtablename.length-3)+'V'+subtablename.substring(subtablename.length-2);

          }
            getqueryfieldList({
                categoryId: this.info.categoryId,
                menuId: this.$route.meta.menuId,
                subTableName: subtablename
            }).then(response => {
                this.listFrom = response.rows;
            });
        },

        //获取总数/初审分配数/复审分配数
        getcsfsallnumbyrenwuidPost() {
            getcsfsallnumbyrenwuid(this.info.ID).then(res => {
                if (res.data.length > 0) {
                    this.numInfo = res.data[0]
                }

            })
        },

        //获取表头列表
        getshowfieldPost() {
            var level = "";
            if (getLastIndexOf(this.info.SUB_TABLE_NAME) == "F") {  //F 件
                level = "jian"
            } else if (getLastIndexOf(this.info.SUB_TABLE_NAME) == "V") { //卷
                level = "juan"
            } else { //项目
                // level = "xiangmu"
                level = "juan"
            }
            this.loading = true;
            getshowfield({
                categoryId: this.info.categoryId,
                level: level,
                menuId: this.$route.meta.menuId
            }).then(res => {
                this.loading = false;
                this.tableHeaderList = res.data;
                for (var i in res.data) {
                    this.fields.push(res.data[i].FIELD_NAME)
                }
                this.getdatalistbyrenwuidPost()

            })
        },

        //获取任务单内的档案数据列表
        getdatalistbyrenwuidPost() {
            getdatalistbyrenwuid({
                renwuid: this.info.ID,
                fields: this.fields.toString(),
                menuId: this.$route.meta.menuId,
                pageNum: this.pageNum,
                pageSize: this.pageSize,
                searchcolumn: this.searchcolumn,
                chushenstate: this.chushenstate,//初审状态
                fushenstate: this.fushenstate,//复审状态
                order: this.order
            }).then(res => {

                this.tableData = res.rows;
                this.total = res.total;

            })
        },

        closeDelDialog() {
            this.$emit("closeDelDialog")
        },



        //onChangeTap时间
        onChangeTap(data) {
            var dataArr=""
            if(data.val!=undefined){
              dataArr = data.queryParams;
            }else{
              dataArr = data;
            }
            if (this.queryParams.length > 0) {
                for (var i in this.queryParams) {
                    if (Object.keys(this.queryParams[i]).toString() == Object.keys(data).toString()) {
                        this.queryParams.splice(i, 1)
                    }
                }
                this.queryParams = dataArr;
            } else {
                this.queryParams = dataArr;
            }

        },
        handleQuery() {
            var searchcolumn = []
            for (var k in this.listFrom) {
                for (var i in this.queryParams) {
                  console.log(this.listFrom[k])
                  if(this.queryParams[i] != null) {
                    if (this.listFrom[k].FIELD_NAME == i) {
                      if (this.listFrom[k].SHOWTYPE == 3&&this.listFrom[k].IS_QUERY == 4) {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME,
                          "value": this.queryParams[i][0],
                          "valueTwo": this.queryParams[i][1],
                        })
                      } else {
                        searchcolumn.push({
                          "queryType": this.listFrom[k].IS_QUERY,
                          "showType": this.listFrom[k].SHOWTYPE,
                          "column": this.listFrom[k].FIELD_NAME,
                          "value": this.queryParams[i],

                        })
                      }
                    }
                  }


                }
            }

            this.searchcolumn = searchcolumn;
            this.getdatalistbyrenwuidPost();
        },


        //重置
        resetQuery() {
            this.queryParams = {};
            this.searchcolumn = [];
            this.chushenstate = undefined;
            this.fushenstate = undefined;
            this.getdatalistbyrenwuidPost();
        },
        //排序
        sortChange(val) {
            this.order = val;
            this.getdatalistbyrenwuidPost();
        },
        //0: 初审手动分配,1:初审平均分配,2:复审手动分配,3:复审平均分配,4:重新初审分配,5:重新复审分配,6:人员调整
        onTaskTap(val) {
            var that=this
            if (val == 4) {

                this.$modal.confirm('确定重新初审分配？').then(function () {
                    refp({
                        renwuid: that.rowInfo.ID,
                        type: "chushen"
                    }).then(res => {
                        if (res.code == "200") {
                            that.$modal.msgSuccess("操作成功");
                            that.getcsfsallnumbyrenwuidPost();
                        }
                    })

                }).catch(() => { });

            } else if (val == 5) {
                this.$modal.confirm('确定重新复审分配？').then(function () {
                    refp({
                        renwuid: that.rowInfo.ID,
                        type: "fushen"
                    }).then(res => {
                        if (res.code == "200") {
                            that.$modal.msgSuccess("操作成功");
                            that.getcsfsallnumbyrenwuidPost();
                        }
                    })

                }).catch(() => { });
            } else if(val==6){
                this.turnOpen=true;
            }else {
                this.openIs = true;
                this.rowInfo.openIs = true;
                this.rowInfo.isRyType = val//0: 初审手动分配,1:初审平均分配,2:复审手动分配,3:复审平均分配,4:重新初审分配,5:重新复审分配,6:人员调整
            }
        },
        closeDialog(){
            this.turnOpen=false;
        },
        closeDelfindDialog() {
            this.openIs = false;
            this.rowInfo.openIs = false;
            this.getcsfsallnumbyrenwuidPost();//获取总数/初审分配数/复审分配数
        },
    }

}
</script>
<style lang="scss" scoped="scoped" >
.eldialog ::v-deep .el-dialog__body {
    padding: 10px 20px 25px !important;
}

.eldialog ::v-deep .el-dialog {
    // padding: 0 20px 20px 20px !important;
    display: flex;
    flex-direction: column;
    margin: 0 !important;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: calc(100% - 30px);
    max-width: calc(100% - 30px);
}

.eldialog ::v-deep .el-dialog .el-dialog__body {
    flex: 1;
    overflow-x: hidden;
}

.eldialog ::v-deep ::v-deep .el-form-item__content {
    line-height: 26px;
}

.el-divider {
    margin-top: 0;
}

.eldialog .elinput {
    border: 0 !important
}
</style>
